package com.qltv.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

import com.qltv.thread.TokenThread;
/**
 * 
 * 类名：InitServlet
 * 描述：初始化servlet
 * @author telnet
 * 创建时间：2018年1月12日
 */
public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = 3942221423011325018L;

	private static final Logger logger = Logger.getLogger(InitServlet.class);
	
	@Override
	public void init() throws ServletException {
		//获取web.xml中配置的参数
		TokenThread.appid = getInitParameter("appid");
		TokenThread.appsecret = getInitParameter("appsecret");
		
		logger.info("wexin api appid:"+TokenThread.appid);
		logger.info("wexin api appsecret:"+TokenThread.appsecret);
		
		//未配置appid、appsecret时给出提示
		if("".equals(TokenThread.appid) || "".equals(TokenThread.appsecret)){
			logger.error("appid and appsecret configuration error, please check carefully.");
		}else{
			//启动定时获取access_token的线程
			new Thread(new TokenThread()).start();
		}
	}
}
